# -*- coding: utf-8 -*-

"""
 (c) 2023 - Copyright CTyunOS Inc

 Authors:
   youyifeng <youyf2@chinatelecom.cn>

"""

from optparse import OptionParser

import logging

logger = logging.getLogger('cve-ease')


def get_usage_str(usage):
    return usage + "\n(Specify the --help global option for a list of other help options)"


def handle_config(gconfig, db_session, args):
    """[basic] Print cve-ease config"""
    usage = "usage: %prog config <options>"
    parser = OptionParser(usage=get_usage_str(usage))

    parser.add_option('-r', '--rawdata', dest='raw', action='store_true', default=False,
                      help='print raw config file content')
    (options, args) = parser.parse_args(args)

    if options.raw:
        print(" config file is in", gconfig.configFile)
        with open(gconfig.configFile, 'r') as configfile:
            print(configfile.read())
    else:
        print(" config file is in", gconfig.configFile)
        with open(gconfig.configFile, 'r') as configfile:
            config = configfile.readlines()
        for line in config:
            if line.strip() == '':
                continue
            elif line.strip().startswith('#'):
                continue
            print(line.strip())
